package com.zzy.blog.json.jsonlib;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * object----->jsonStr
 * josnStr----->object稍微复杂点
 * @author eason
 *
 */
public class JsonTest {
	
	//测试bean
	public static House house = new House();
	public static Teacher teacher = new Teacher();
	public static Student student = new Student();
	public static School school = new School();
	
	public static List<Student> stuList = new ArrayList<Student>();
	public static Student[] stus = new Student[2];
	
	
	public static List<Teacher> teachers = new ArrayList<Teacher>();
	public static List<House> houses = new ArrayList<House>();
	
	
	static {
		house.setPrice(10000L);
		houses.add(house);
		
		teacher.setSex("male");
		teacher.setHouse(house);
		
		
		teachers.add(teacher);
		teachers.add(teacher);
		
		
		student.setAge(18);
		student.setName("zhangsan");
		
		
		
		for (int i = 0; i < stus.length; i++) {
			stus[i] = new Student();
			stus[i].setAge(i * 10 + 8);
			stus[i].setName("zhang" + i);
			stuList.add(stus[i]);
		}
		
		school.setStudents(stuList);
		school.setTeachers(teachers);
		school.setTeacher(teacher);
		school.setAge(12);
		school.setName("sc nam");
		
	}
	
	
	public static void main(String[] args) {
		
		//6.1
		//object(属性有list)----->jsonString
		String jsonStr8 = JsonUtils.getJsonString(school);
		System.out.println(jsonStr8);
		
		//6.2
		//jsonString----->object(属性有list)
		Map<String, Class> clazzMap = new HashMap<String, Class>();
		clazzMap.put("students", Student.class);
		clazzMap.put("teachers", Teacher.class);
		
		School school = JsonUtils.getObject(jsonStr8, School.class, clazzMap);
		System.out.println(school.getTeacher() instanceof Teacher);
		System.out.println(school.getStudents().get(0) instanceof Student);
		System.out.println(school.getTeachers().get(0) instanceof Teacher);
		System.out.println(school.getTeachers().get(0).getHouse() instanceof House);
		System.out.println("======================================================7==========================================================================================");

		
	}	
	
	
	
	
}
